package com.winsdom.controller.Header;

import com.winsdom.controller.WriteOffRecordController;
import com.winsdom.domain.dto.HandsDto;
import com.winsdom.dto.UnclearedDTO;
import com.winsdom.entity.CustomerBillingHeader;
import com.winsdom.entity.InvoiceApplication;
import com.winsdom.result.PageResult;
import com.winsdom.result.Result;
import com.winsdom.service.ICustomerBillingHeaderService;
import com.winsdom.service.IInvoiceApplicationService;
import com.winsdom.service.IWriteOffRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = "抬头公司信息查询")
public class HeaderSelect {
    @Autowired
    private ICustomerBillingHeaderService iCustomerBillingHeaderService;
    @Autowired
    private WriteOffRecordController writeOffRecordController;
    @Autowired
    private IWriteOffRecordService iWriteOffRecordService;

    @GetMapping("/header")
    @ApiOperation("获取抬头公司的详细信息")
    public Result getUnclearedBills(@RequestParam(value = "projectName") String projectName) {
//        调用方法根据名字获取抬头显示信息
        CustomerBillingHeader customerBillingHeader = iCustomerBillingHeaderService.getHeder(projectName);
        if (customerBillingHeader == null) {
            return Result.error("抬头公司不存在");
        }
        else {
            return Result.success(customerBillingHeader);
    }
    }
    @PostMapping("/hander")
    @ApiOperation("手动核销")
    public Result Hands(@RequestBody HandsDto handsDto) {
        // 调用方法手动核销
      boolean result = iWriteOffRecordService.hands(handsDto);
      if (result) {
          return Result.success("手动核销成功");
      }else{
          return Result.error("手动核销失败");
      }
    }

}
